Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upCannot bundle Pillow using py2app on macOS #4001
Comments
This comment has been minimized.
This comment has been minimized.
What version of py2app are you using? I ask as this is a known issue for py2app - https://bitbucket.org/ronaldoussoren/py2app/issues/219/new-mach-o-header-is-too-large-to-relocate - and updating might fix it. |
This comment has been minimized.
This comment has been minimized.
Thanks for the prompt reply! I have tried with a couple different py2app versions, including the latest versions of both py2app and macholib (0.19 and 1.11, respectively), and the problem still occurs. Note also the last two comments in that thread, from June, saying they still are having the issue, and reporting how they fixed it by recompiling Pillow. It looks like the FAQ on this issue also still recommends recompiling libraries that trigger this issue: https://py2app.readthedocs.io/en/latest/faq.html I've compiled C++ / Obj-C macOS apps as well, and it's important in those cases too to specify |
This comment has been minimized.
This comment has been minimized.
Thanks. If you're willing to go through the process of putting together a reproducible app, that would be interesting - one that works without Pillow, but fails with Pillow. You should be able to upload a zip in a comment on this issue. My other question to help with reproducibility is - how did you install your Python libraries? |
This comment has been minimized.
This comment has been minimized.
Also, while not related to your issue, be aware that in 2020, Pillow will no longer support Python 2.7, Pillow being committed to https://python3statement.org/ |
This comment has been minimized.
This comment has been minimized.
Sorry for the delayed reply! My Mac laptop had a swollen battery and it took it about a week to get it fixed and restored, making it difficult to put together a sample Mac app! Now that I'm up and running again, here is a minimal sample application: Please let me know if you have any questions about it, etc. Hopefully the |
This comment has been minimized.
This comment has been minimized.
Oh, I didn't make a version that works without Pillow, but if you comment out the Pillow usage in |
This comment has been minimized.
This comment has been minimized.
Thanks. I'm able to replicate using TravisCI. To link the issues, this is the re-emergence of #3297 |
This comment has been minimized.
This comment has been minimized.
Testing, I find that Pillow 5.3 works. To check that I am correctly reproducing your situation, could you tell me if it works for you? |
This comment has been minimized.
This comment has been minimized.
Yes, it does! When I use |
This comment has been minimized.
This comment has been minimized.
I ran into this as well. PIL's littlecms dependency needs an additional linker flag ( Here is a very short reproducible example:
I am running macOS 10.14.6 with homebrew Python 3.7.7 and Pillow 7.1.1. As asked above ( #4001 (comment) ), this error does not occur with Pillow 5.3. The other related issue ( #3297 ) says the non-relocatability of Someone on stackoverflow ( https://stackoverflow.com/questions/56604893/python-py2app-and-pillow-error-mach-o-header-is-too-large ) fixed the problem by recompiling littlecms with the aforementioned linker flag. They also suggested just deleting Here are the commands without output for copying-and-pasting:
The full output is attached: reproduce.txt |
What did you do?
Tried to bundle python apps that use Pillow into a .app bundle on macOS using py2app.
What did you expect to happen?
A working .app bundle of my Python code would be produced.
What actually happened?
py2app failed to properly bundle Pillow due to an issue with re-writing the dylib install path when moving the dependency dylibs into the app bundle. The reported error is:
ValueError: New Mach-O header is too large to relocate in '/code/LearningEquality/exelearning/dist/exe.app/Contents/Resources/lib/python2.7/PIL/.dylibs/liblcms2.2.dylib' (new size=1688L, max size=1680L, delta=48L)
I was able to fix this locally by rebuilding Pillow after recompiling the homebrew dependencies with the following added linker flags:
-Wl,-headerpad_max_install_names
What are your OS, Python and Pillow versions?
I could work on a reproducible app if needed, but it would need at least two files, a setup.py file and a main.py that imports pillow, so would probably upload a zip somewhere. If the code for installing the brew dependencies on macOS are in the repo, would be happy to submit a PR with the fix.